Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose bind leader directly #4836

Merged
merged 3 commits into from
Apr 12, 2018

Conversation

christophermaier
Copy link
Contributor

Previously, determining the leader of a service group was
complicated. If the service was running in a leader topology, the
{{bind.<BIND>.first}} key would be the leader, but we didn't
directly indicate if that was the case (you could have queried to see
if {{bind.<BIND>.first.leader}} was true, but that leads to some
needlessly verbose templates.

Now, we introduce an explicit leader key, which will be non-null if
the service group has a leader. Furthermore, the use of first is
deprecated, since the meaning of it is not deterministic (it could be
a non-alive member of the service group, for instance, which is not
what anyone wants). The first key will remain in rendering contexts
for the foreseeable future, but users are encouraged to use
{{bind.<BIND>.leader}} if they want the leader, and
{{bind.<BIND>.members[0]}} otherwise, pending future refactorings.

Documentation is updated to reflect this, and a new $deprecated and
$since key are used in our JSON Schema to indicate when an old field
is deprecated, and when a new one is introduced. Our JSON Schema
parser is configured to allow non-standard keywords like this through
its processing, and this provides some additional hooks that a future
automated documentation generator can use (see #4824)

Fixes #4127

@thesentinels
Copy link
Contributor

Thanks for the pull request! Here is what will happen next:

  1. Your PR will be reviewed by the maintainers
  2. If everything looks good, one of them will approve it, and your PR will be merged.

Thank you for contributing!

@@ -478,8 +478,17 @@
"properties": {
"first": {
"description": "The first member of this service group. If the group is running in a leader topology, this will also be the leader.",
"$deprecated": "Since 0.56.0; if you want the leader, use `leader` explicitly. 'first' isn't deterministic, either, so you can just use `members[0]` instead",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not up on the whole handlebars world, but I remember seeing something about the syntax changing to something like members.[0]. Does that apply here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baumanj Habitat's current syntax is foo[0], but the Handlebars library we use recently fixed itself to use the proper foo.[0] syntax. We can't upgrade our Handlebars library right now, though, because it would break any template that has the foo[0] syntax. So, until then, we have to keep the old way around 😦

@baumanj
Copy link
Contributor

baumanj commented Mar 29, 2018

leader
Obscure?

@irvingpop
Copy link

hey @christophermaier I'm thinking we should include a generic example in the documentation, like what's in the postgresql plan README here: https://github.com/irvingpop/habitat-core-plans/blob/master/postgresql/README.md#binding

If I'm interpreting this PR correctly, would this be the right syntax?

{{~ #if bind.database}}
  {{~ #if bind.database.leader}}
PGHOST="{{bind.database.leader.sys.ip}}"
  {{else}}
PGHOST="{{bind.database.members[0].sys.ip}}"
  {{~ /if}}
{{~ /if}}

right?

@christophermaier
Copy link
Contributor Author

@baumanj Manos: The Templates of Fate

@christophermaier
Copy link
Contributor Author

@irvingpop Yup, you've got the idea 👍

@irvingpop
Copy link

After sleeping on this, I'm wondering if we could use this opportunity to improve the UX a bit - since this if/else statement will wind up in everyone's plans - would you consider some ideas to make it more terse and expressive?

some ideas in no particular order:

  • bind.BIND.leader always returns something - if not in a topology, then a random alive member
  • same as above, but call it bind.BIND.auto - the idea is to try to do the right thing in any scenario

some users may also prefer going the other way and wanting more control:

  • bind.BIND.topology - returns the topology type
  • bind.BIND.followers, bind.BIND.anyfollower
  • bind.BIND.members.count, also newest, oldest, etc - should be self explanatory and only give you Alive members
  • bind.BIND.members.dead - enumerate the list of departed members that the ring still knows about

@christophermaier
Copy link
Contributor Author

Just to make things visible... @irvingpop and I will be chatting more about ideas for improving template data next week. It's fine for this PR to stay open until at least then.

@christophermaier
Copy link
Contributor Author

Had a chat with @irvingpop and captured ideas for the future in ##4872.

Nothing affects the correctness or suitability of this PR, so it's open again to comment and merging.

Copy link
Collaborator

@reset reset left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm loving what you are doing with the rendering context schema. These improvements are huge. Also yes to bind.{x}.leader.

It's worth mentioning to any reader who is unaware, the reason we had so much duplicated data was because we first started with mustache as our rendering engine and later changed to handlebars. These changes have been a long time coming since that switch (back in 2016 😬)

Copy link
Contributor

@eeyun eeyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christophermaier christophermaier force-pushed the cm/4127-expose-bind-leader-directly branch from 1536148 to 16f6009 Compare April 9, 2018 14:43
Signed-off-by: Christopher Maier <[email protected]>
Previously, determining the leader of a service group was
complicated. If the service was running in a leader topology, the
`{{bind.<BIND>.first}}` key would be the leader, but we didn't
directly indicate if that was the case (you could have queried to see
if `{{bind.<BIND>.first.leader}}` was `true`, but that leads to some
needlessly verbose templates.

Now, we introduce an explicit `leader` key, which will be non-null if
the service group has a leader. Furthermore, the use of `first` is
deprecated, since the meaning of it is not deterministic (it could be
a non-alive member of the service group, for instance, which is not
what anyone wants). The `first` key will remain in rendering contexts
for the foreseeable future, but users are encouraged to use
`{{bind.<BIND>.leader}}` if they want the leader, and
`{{bind.<BIND>.members[0]}}` otherwise, pending future refactorings.

Documentation is updated to reflect this, and a new `$deprecated` and
`$since` key are used in our JSON Schema to indicate when an old field
is deprecated, and when a new one is introduced. Our JSON Schema
parser is configured to allow non-standard keywords like this through
its processing, and this provides some additional hooks that a future
automated documentation generator can use (see #4824)

Fixes #4127

Signed-off-by: Christopher Maier <[email protected]>
@christophermaier christophermaier force-pushed the cm/4127-expose-bind-leader-directly branch from 16f6009 to f2e4467 Compare April 12, 2018 14:26
@christophermaier christophermaier merged commit ad17d83 into master Apr 12, 2018
@christophermaier christophermaier deleted the cm/4127-expose-bind-leader-directly branch April 12, 2018 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants